<?php
/**
 * Created by PhpStorm.
 * User: dev
 * Date: 6/10/14
 * Time: 2:41 PM
,,*/

class Products_Autocomplete_Controller extends Base_Controller {

    public $restful = true;

    public function __construct()
    {
        parent::__construct();
    }

    public function get_products(){

        $term = $_GET["q"];
        $cid = Products::select(array('id','title'))->where('title', 'LIKE', $term.'%')->take(7)->get();

        if($cid) {
            foreach ($cid as $row){
                $answer[] = array("id"=>$row->id,"text"=>$row->title);
            }
        } else {
            // 0 results send a message back to say so.
            $answer[] = array("id"=>"0","text"=>"No Results Found..");
        }


        echo json_encode($answer);//format the array into json data
    }

    
} 